<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{title}}</title>

</head>
<body>
<button>发送短信</button>
<input type="text" placeholder="请输入手机号">
<input type="text" placeholder="请输入验证码">
<input type="password" placeholder="请输入密码">
<button>验证</button>

</body>
</html>
<script src="/js/jquery.min.js"></script>
<script src="/js/bmob-min.js"></script>
<script>

    Bmob.initialize("d62c7de09f8f81cf326210b5a9ecd57f", "b78fb836e687b514a43ff500bf8b9dbe");

    var button1 = document.getElementsByTagName('button')[0];
    var button2 = document.getElementsByTagName('button')[1];
    var input1 = document.getElementsByTagName('input')[0];
    var input2 = document.getElementsByTagName('input')[1];
    var input3 = document.getElementsByTagName('input')[1];

    var vrcid;
    button1.onclick = function () {
        var number = input1.value;
        console.log('aaa');
        console.log(number);
        Bmob.Sms.requestSmsCode({"mobilePhoneNumber": number,"template":"短信"} ).then(function(obj) {
//            vrcid = obj.smsId;

            Bmob.Sms.querySms(obj.smsId).then(function(obj) {
                alert("status:"+obj.sms_state); //
                if(obj.sms_state == 'SENDING'){
                    alert('短信发送成功')
                }
            }, function(err){
                alert("发送失败2:"+err);
            });
        }, function(err){
            alert("发送失败1:"+err.message);
        });
    };
    button2.onclick = function () {
        var number = input1.value;
        var vrc = input2.value;
        var psw= input3.value;

        Bmob.Sms.verifySmsCode(number, vrc).then(function(obj) {
            alert("msg:"+obj.msg); //
            if(obj.msg == 'ok'){
                var data  = {number:number,psw:psw};
                $.get('/users/register',data,function (resDate) {
                    alert('注册成功');
                    console.log(resDate.username);

                });
            }

        }, function(err){
            alert("发送失败3:"+err);
        });


    };



</script>